package com.ma4567.remotecontroller.util;

import com.ma4567.remotecontroller.RemoteControllerApplication;
import com.ma4567.remotecontroller.UserManager.LoggedUser;

public class Cookie {
    public static final String letter = "0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";

    public static String GetCookie(int CookieLength){
        while(true){
            boolean CookieExisted = false;

            String cookie = "";
            for(int i = 0; i < CookieLength; i++){
                cookie = cookie + letter.charAt((int)(Math.random() * letter.length() + 0));
            }

            for(LoggedUser u : RemoteControllerApplication.userManager.loggedUsers){
                if(u.Cookie.equals(cookie)){
                    CookieExisted = true;
                }
            }

            if(!CookieExisted){
                return cookie;
            }
        }
    }
}
